package com.shenmazong.servernewsapi.controller;

import com.shenmazong.utils.ResponseResult;
import com.shenmazong.servernewsapi.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Slf4j
@ApiIgnore
public class NewsController {

    @Autowired
    NewsService newsService;

    @PostMapping(value = "/addUserNews")
    public ResponseResult addUserNews(@RequestParam("userId") Integer userId,
                                      @RequestParam("longitude") Double longitude,
                                      @RequestParam("latitude") Double latitude,
                                      @RequestParam("serviceType") Integer serviceType,
                                      @RequestParam("title") String title,
                                      @RequestParam("content") String content) {
        return newsService.addUserNews(userId, longitude, latitude, serviceType, title, content);
    }

    @PostMapping(value = "/delUserNews")
    public ResponseResult delUserNewsById(@RequestParam("userId") Integer userId,
                                  @RequestParam("newsId") Integer newsId) {
        return newsService.delUserNewsById(userId, newsId);
    }

    @PostMapping(value = "/setUserNews")
    public ResponseResult setUserNews(@RequestParam("userId") Integer userId,
                                      @RequestParam("newsId") Integer newsId,
                                      @RequestParam("longitude") Double longitude,
                                      @RequestParam("latitude") Double latitude,
                                      @RequestParam("serviceType") Integer serviceType,
                                      @RequestParam("title") String title,
                                      @RequestParam("content") String content) {
        return newsService.setUserNews(userId, newsId, longitude, latitude, serviceType, title, content);
    }

    @PostMapping(value = "/getNewsByUserId")
    public ResponseResult getNewsByUserId(@RequestParam("userId") Integer userId,
                                          @RequestParam("pageNo") Integer pageNo,
                                          @RequestParam("pageSize") Integer pageSize) {
        return newsService.getNewsByUserId(userId, pageNo, pageSize);
    }

    @PostMapping(value = "/getNewsByTypeId")
    public ResponseResult getNewsByTypeId(@RequestParam("userId") Integer userId,
                                          @RequestParam("typeId") Integer typeId,
                                          @RequestParam("pageNo") Integer pageNo,
                                          @RequestParam("pageSize") Integer pageSize) {
        return newsService.getNewsByTypeId(userId, typeId, pageNo, pageSize);
    }

    @PostMapping(value = "/getNewsByCircle")
    public ResponseResult getNewsByCircle(@RequestParam("userId") Integer userId,
                                          @RequestParam("longitude") Double longitude,
                                          @RequestParam("latitude") Double latitude,
                                          @RequestParam("distance") Long distance
                                          ) {
        return newsService.getNewsByCircle(userId, longitude, latitude, distance);
    }

    @PostMapping(value = "/getNewsByKeyword")
    public ResponseResult getNewsByKeyword(String keyWord) {
        return newsService.getNewsByKeyword(keyWord);
    }

    @PostMapping(value = "/doClickOk")
    public ResponseResult doClickOk(@RequestParam("userId") Integer userId,
                                    @RequestParam("newsId") Integer newsId) {
        return newsService.doClickOk(userId, newsId);
    }

    @PostMapping(value = "/ResponseResult")
    public  ResponseResult doClickOkQuick(@RequestParam("userId") Integer userId,
                                          @RequestParam("newsId") Integer newsId) {
        return newsService.doClickOkQuick(userId, newsId);
    }

    @PostMapping(value = "/uploadNewsImage")
    public ResponseResult uploadNewsImage(Integer userId, MultipartFile file) {
        return newsService.uploadNewsImage(userId, file);
    }
}
